package Logicamente;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.GridBagLayout;

import javax.swing.JButton;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.ImageIcon;

import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Cursor;

import org.eclipse.wb.swing.FocusTraversalOnArray;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaFinDeJuego extends JFrame {

	private JPanel contentPane;
	private JButton btnDatos;
	private JButton btnCompartir;
	private JLabel jLabel_mono;
	private JButton btnResultado;
	private JButton btnVolver;
	
	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					VentanaFinDeJuego frame = new VentanaFinDeJuego(0,0,null,null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public VentanaFinDeJuego(final int tiempo, final int resp,final Usuario u, final Partida p) {
		setIconImage(Toolkit.getDefaultToolkit().getImage(VentanaFinDeJuego.class.getResource("/Imagenes/L.png")));
		setTitle("Logicamente");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 500, 400);
		contentPane = new JPanelConFondo("/Imagenes/fondo.jpg");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel_superior = new JPanelConFondo("/Imagenes/fondo_t.png");
		contentPane.add(panel_superior, BorderLayout.NORTH);
		
		JLabel lblLaPartidaHa = new JLabel("La partida ha finalizado");
		lblLaPartidaHa.setFont(new Font("DejaVu Sans", Font.PLAIN, 28));
		panel_superior.add(lblLaPartidaHa);
		
		JPanel panel_inferior = new JPanelConFondo("/Imagenes/fondo_t.png");
		contentPane.add(panel_inferior, BorderLayout.SOUTH);
		GridBagLayout gbl_panel_inferior = new GridBagLayout();
		gbl_panel_inferior.columnWidths = new int[] {30, 100, 100, 100, 100, 30};
		gbl_panel_inferior.rowHeights = new int[]{0, 0, 0};
		gbl_panel_inferior.columnWeights = new double[]{100.0, 0.0, 0.0, 0.0, 0.0, 100.0};
		gbl_panel_inferior.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		panel_inferior.setLayout(gbl_panel_inferior);
		
		JLabel lblDatosPartida = new JLabel("Datos partida");
		lblDatosPartida.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
		GridBagConstraints gbc_lblDatosPartida = new GridBagConstraints();
		gbc_lblDatosPartida.fill = GridBagConstraints.VERTICAL;
		gbc_lblDatosPartida.insets = new Insets(0, 0, 5, 5);
		gbc_lblDatosPartida.gridx = 1;
		gbc_lblDatosPartida.gridy = 0;
		panel_inferior.add(lblDatosPartida, gbc_lblDatosPartida);
		
		JLabel lblResultados = new JLabel("Resultados");
		lblResultados.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
		GridBagConstraints gbc_lblResultados = new GridBagConstraints();
		gbc_lblResultados.fill = GridBagConstraints.VERTICAL;
		gbc_lblResultados.insets = new Insets(0, 0, 5, 5);
		gbc_lblResultados.gridx = 2;
		gbc_lblResultados.gridy = 0;
		panel_inferior.add(lblResultados, gbc_lblResultados);
		
		JLabel lblCompartir = new JLabel("Compartir");
		lblCompartir.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
		GridBagConstraints gbc_lblCompartir = new GridBagConstraints();
		gbc_lblCompartir.fill = GridBagConstraints.VERTICAL;
		gbc_lblCompartir.insets = new Insets(0, 0, 5, 5);
		gbc_lblCompartir.gridx = 3;
		gbc_lblCompartir.gridy = 0;
		panel_inferior.add(lblCompartir, gbc_lblCompartir);
		
		JLabel lblMenuPrincipal = new JLabel("Menu Principal");
		lblMenuPrincipal.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
		GridBagConstraints gbc_lblMenuPrincipal = new GridBagConstraints();
		gbc_lblMenuPrincipal.fill = GridBagConstraints.VERTICAL;
		gbc_lblMenuPrincipal.insets = new Insets(0, 0, 5, 5);
		gbc_lblMenuPrincipal.gridx = 4;
		gbc_lblMenuPrincipal.gridy = 0;
		panel_inferior.add(lblMenuPrincipal, gbc_lblMenuPrincipal);
		
		btnDatos = new JButton("");
		btnDatos.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnDatos.setIcon(new ImageIcon(VentanaFinDeJuego.class.getResource("/Imagenes/boton_datospartida_f.png")));
		btnDatos.setPreferredSize(new Dimension(70, 70));
		GridBagConstraints gbc_btnDatos = new GridBagConstraints();
		gbc_btnDatos.insets = new Insets(0, 0, 0, 5);
		gbc_btnDatos.gridx = 1;
		gbc_btnDatos.gridy = 1;
		panel_inferior.add(btnDatos, gbc_btnDatos);
		btnDatos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				actionBtnDatos(arg0,tiempo,resp,u,p);
			}
		});
		
		btnResultado = new JButton("");
		btnResultado.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnResultado.setIcon(new ImageIcon(VentanaFinDeJuego.class.getResource("/Imagenes/boton_resultados_f.png")));
		btnResultado.setPreferredSize(new Dimension(70, 70));
		GridBagConstraints gbc_btnResultado = new GridBagConstraints();
		gbc_btnResultado.insets = new Insets(0, 0, 0, 5);
		gbc_btnResultado.gridx = 2;
		gbc_btnResultado.gridy = 1;
		panel_inferior.add(btnResultado, gbc_btnResultado);
		
		btnCompartir = new JButton("");
		btnCompartir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				actionBtnCompartir(arg0);
			}
		});
		btnCompartir.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnCompartir.setIcon(new ImageIcon(VentanaFinDeJuego.class.getResource("/Imagenes/boton_compartir_f.png")));
		btnCompartir.setPreferredSize(new Dimension(70, 70));
		GridBagConstraints gbc_btnCompartir = new GridBagConstraints();
		gbc_btnCompartir.insets = new Insets(0, 0, 0, 5);
		gbc_btnCompartir.gridx = 3;
		gbc_btnCompartir.gridy = 1;
		panel_inferior.add(btnCompartir, gbc_btnCompartir);
		
		btnVolver = new JButton("");
		btnVolver.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				actionBtnVolver(arg0, u,  p);
			}
		});
		btnVolver.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnVolver.setIcon(new ImageIcon(VentanaFinDeJuego.class.getResource("/Imagenes/boton_volver_f.png")));
		btnVolver.setPreferredSize(new Dimension(70, 70));
		GridBagConstraints gbc_btnVolver = new GridBagConstraints();
		gbc_btnVolver.insets = new Insets(0, 0, 0, 5);
		gbc_btnVolver.gridx = 4;
		gbc_btnVolver.gridy = 1;
		panel_inferior.add(btnVolver, gbc_btnVolver);
		
		JPanel panel_central = new JPanelConFondo("/Imagenes/fondo_t.png");
		contentPane.add(panel_central, BorderLayout.CENTER);
		{
			jLabel_mono = new JLabel();
			jLabel_mono.setHorizontalTextPosition(SwingConstants.CENTER);
			jLabel_mono.setHorizontalAlignment(SwingConstants.CENTER);
			panel_central.add(jLabel_mono);
			jLabel_mono.setPreferredSize(new java.awt.Dimension(480, 201));
			jLabel_mono.setIcon(new ImageIcon(VentanaFinDeJuego.class.getResource("/Imagenes/monito_f.png")));
		}
		setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{btnDatos, btnResultado, btnCompartir, btnVolver}));
	}
	
	protected void actionBtnDatos(ActionEvent arg0,int tiempo, int resp, Usuario u,Partida p) {
		VentanaDatosPartida v = new VentanaDatosPartida(tiempo,resp,u,p);
		v.setLocationRelativeTo(null);
		v.setVisible(true);                    
		this.setVisible(false);
		this.hide();
	}

	protected void actionBtnVolver(ActionEvent arg0,Usuario u,Partida p) {
		VentanaUsuario v = new VentanaUsuario(u);
		v.setLocationRelativeTo(null);
		v.setVisible(true);                    
		this.setVisible(false);
		this.hide();
	}
	
	protected void actionBtnCompartir(ActionEvent arg0) {
		DialogoCompartir v = new DialogoCompartir(this);
		v.setLocationRelativeTo(null);
		v.setVisible(true);                    
		activar(false);
	}
	
	public void activar(boolean b)
	{
		btnDatos.setEnabled(b);
		btnCompartir.setEnabled(b);
		btnResultado.setEnabled(b);
		btnVolver.setEnabled(b);
		if (b==false)
			this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		else
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
